package cc.admin.modules.sys.controller;

import cc.admin.common.api.vo.Result;
import cc.admin.common.aspect.annotation.AutoLog;
import cc.admin.common.sys.query.QueryGenerator;
import cc.admin.common.sys.vo.LoginUser;
import cc.admin.modules.sys.entity.SystemMessage;
import cc.admin.modules.sys.service.ISystemMessageService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Api(tags="")
@RestController
@RequestMapping("/system/messageRecording")
public class SystemMessageController {
    @Autowired
    private ISystemMessageService systemMessageService;

    /**
     * 分页列表查询
     *
     * @param key
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "-分页列表查询")
    @ApiOperation(value="-分页列表查询", notes="-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(
            SystemMessage systemMessage,
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
            HttpServletRequest req) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<SystemMessage> queryWrapper = QueryGenerator.initQueryWrapper(new SystemMessage(), req.getParameterMap());
        if (systemMessage.getMessageHeader()!=null&&systemMessage.getMessageHeader()!="") {
            queryWrapper.like("message_header", systemMessage.getMessageHeader());
        }
        queryWrapper.eq("user_id", sysUser.getId());
        Page<SystemMessage> page = new Page<SystemMessage>(pageNo, pageSize);
        IPage<SystemMessage> pageList = systemMessageService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

}
